import Mock from 'mockjs'

const data = [
    {
        title: "西瓜",
        id: 1,
        img: "https://img1.baidu.com/it/u=172822880,3283292092&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500"
    },
    {
        title: "苹果",
        id: 2,
        img: "https://img1.baidu.com/it/u=2806546300,382552044&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=750"
    },
    {
        title: "香蕉",
        id: 3,
        img: "https://img2.baidu.com/it/u=3420484142,1981428872&fm=253&fmt=auto&app=120&f=JPEG?w=640&h=424"
    },
    {
        title: "榴莲",
        id: 4,
        img: "https://img1.baidu.com/it/u=2768017645,3365184676&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500"
    }
]

Mock.mock('/getList', data)

// 详情页接口
Mock.mock(RegExp('/getDetail' + '*.'), (req) => {
    // 截取id
    const id = req.url.split("=")[1]
    return data.filter(item => item.id == id)[0]
})